﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioManager : Singleton<AudioManager>
{
    private string Key_Voice = "Fly_Card_Voice_";
    
    public bool isOnMute = false;
    public AudioSource m_audioMusic;
    public AudioSource m_audioSound;
    
    public void OnSetAudioPrefab(AudioSource music, AudioSource sound)
    {
        m_audioMusic = music;
        m_audioSound = sound;
        
        OnFirstLoadClip();
        OnGetLocalData();
    }

    public void OnFirstLoadClip()
    {
        m_audioMusic.clip = Resources.Load<AudioClip>("Music/BGM");
        m_audioMusic.Play();
        
        m_audioSound.clip = Resources.Load<AudioClip>("Music/click");
    }
    
    public void OnGetLocalData()
    {
        isOnMute = PlayerPrefs.GetInt(Key_Voice) == 1;
        OnMute(isOnMute);
    }
    public void OnSetLocalData()
    {
        PlayerPrefs.SetInt(Key_Voice, isOnMute ? 1 : 0);
    }
    
    public void OnMute(bool ismute)
    {
        isOnMute = ismute;
        m_audioMusic.mute = ismute;
        m_audioSound.mute = ismute;
    }
    
    public void OnPlayClick()
    {
        m_audioSound.Play();
    }
    public void OnPlayBGM()
    {
        m_audioMusic.Play();
    }
    public bool OnGetMute()
    {
        return isOnMute;
    }
}
